function nameScoreCalc(word) {
    return [...word]
        .reduce((sum, letter) => sum += letter.charCodeAt() - 64, 0);
}

function namesScores(arr) {
    return arr
        .sort((a, b) => a < b ? -1 : a > b ? 1 : 0)
        .reduce((total, word, i) => total += nameScoreCalc(word) * (i + 1), 0);
}

const test1 = ['THIS', 'IS', 'ONLY', 'A', 'TEST'];
const test2 = ['I', 'REPEAT', 'THIS', 'IS', 'ONLY', 'A', 'TEST'];
console.log(namesScores(test1));
console.log(namesScores(test2));
